<?php

	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	//只有是微信访问的情况下，以下设置才生效
	if (strpos($user_agent, 'MicroMessenger') !== false) {
		require_wechat();

		$wechat = new WeChat(-1);
		$appid = $wechat->config['appid'];
		require_once(dirname(BASE_PATH) . '/wxpay/lib/WxPay.Api.php');

		$js = new JsApiPay();
		if(!isset($_COOKIE['openid'])){
			$open_id = $js->GetOpenid();
		?>
			<script>
				addcookie("openid",'<?php echo $open_id;?>');
			</script>
		<?php
		}
		else{
			$open_id = $_COOKIE['openid'];
		}



	}
?>

